import { defineConfig, loadEnv } from "vite";
import createVitePlugins from './vite/plugins'

// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) =>{
  const env = loadEnv(mode, process.cwd())
  const { VITE_APP_BASE_PORT, VITE_APP_BASE_API } = env

  return {
    plugins: createVitePlugins(env, command === 'build'),
    // vite 相关配置
    server: {
      port: VITE_APP_BASE_PORT,
      host: true,
      proxy: {
        [VITE_APP_BASE_API]: {
          target: 'http://localhost:8080/',
          changeOrigin: true,
          rewrite: (p) => p.replace(VITE_APP_BASE_API, "")
            .replace('^' + VITE_APP_BASE_API, ""),
        },
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "./src/assets/styles/index.scss";`
        }
      }
    }
  }
});
